// components/form/form-radio/form-radio.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    label: {
      type: String,
      value: ''
    },
    list:  {
      type: Array,
      value: []
    },
    value: {
      type: Number,
      value: 0
    }
  },

  observers: {
    list(val) {
      if(val.length > 0) {
        this.setData({
          radioList: val
        })
      } 
    },
    value(val) {
      let self = this;
      if(val) {
        self.data.radioList.map((item, index) => {
          if (val == item.id) {
            item.check = 1;
          } else {
            item.check = 2;
          }
        })
        self.setData({
          radioList: self.data.radioList
        })
      }
    }
  },

  data: {
    styleCss: 'padding: 38rpx 0; line-height: 36rpx font-size: 28rpx; border-bottom: 1rpx dashed #f0f0f0;',
    radioList: []
  },

  methods: {
    choose(e) {
      let self = this;
      let idx = e.currentTarget.dataset.idx;
      self.data.radioList.map((item, index) => {
        if (index == idx) {
          item.check = 1;
        } else {
          item.check = 2;
        }
      })
      self.setData({
        radioList: self.data.radioList
      })
      self.triggerEvent('getvalue', {
        val: e.currentTarget.dataset.id
      })
    },
  }
})